/**
 * @file
 * <pre> CPE 464 Winter 2012
 * -------------------
 *
 *  Header to "progrma header"
 *
 *  Last Modified: Sun May 13 01:20:01 AM PDT 2012</pre>
 *  @author Matthew Tondreau
 */

#ifndef _CLIENT_H
#define _CLIENT_H

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "window.h"
#include <setjmp.h>
#include "utility.h"
#define SELECT_SEC 2
#define SELECT_MSEC 0

#define LOCK() { pthread_mutex_lock( &mutex ); }
#define UNLOCK() { pthread_mutex_unlock( &mutex ); }
extern pthread_mutex_t mutex;


enum STATES {
   SETUP,
   LOGIN,
   SELECT,
   UPDATE,
   REFUSED,
   ERROR,
   EXIT
};

extern jmp_buf env;
typedef struct {
   ChatWindows* cw;
   int sk;
} thread_param;
/** defined in .cpp */
void sigint_handler( int i ); 
STATES setup( ChatWindows &cw, int &sk, const char* host, const char* port ); 
int tcp_setup_client(const char* hostname, const char* port); 
STATES login( ChatWindows &cw, int sk);
STATES new_message(const Message &m, ChatWindows &cw);  
void * get_input(void* );
STATES wait_on_select( int sk, Message &m );
STATES refused();
#endif
